package com.example.a22310.myapplication.Model;


import android.app.Service;

import com.example.a22310.myapplication.Beans.ActivityOrder;
import com.example.a22310.myapplication.Beans.Order;
import com.example.a22310.myapplication.Beans.TrainOrder;
import com.example.a22310.myapplication.Listener.ActivityLisenter;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.a22310.myapplication.GloableClass.Yuejian.URL;

public class OrderModel {

    private Retrofit retrofit;
    public OrderModel()
    {

        retrofit= new Retrofit.Builder()
                .baseUrl(URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void orderlist(final ActivityLisenter<Order> lisenter, int userid, int ststus) {
       Service service = retrofit.create(Service.class);
        Call<Order> call = service.orderlist(userid,ststus);
        Callback<Order> callback = new Callback<Order>() {
            @Override
            public void onResponse(Call<Order> call, Response<Order> response) {
                Order activitys = response.body();
                lisenter.onSuccess(activitys);
            }
            @Override

            public void onFailure(Call<Order> call, Throwable t) {
                lisenter.onFailure();
            }
        };
        call.enqueue(callback);
    }

    public void trainOrderlist(final ActivityLisenter<ActivityOrder> lisenter, int userid) {  //培训订单
       Service service = retrofit.create(Service.class);
        Call<ActivityOrder> call = service.activityOrderlist(userid);
        Callback<ActivityOrder> callback = new Callback<ActivityOrder>() {
            @Override
            public void onResponse(Call<ActivityOrder> call, Response<ActivityOrder> response) {
                ActivityOrder activitys = response.body();
                lisenter.onSuccess(activitys);
            }
            @Override

            public void onFailure(Call<ActivityOrder> call, Throwable t) {
                lisenter.onFailure();
            }
        };
        call.enqueue(callback);
    }


    public void activityOrderlist(final ActivityLisenter<TrainOrder> lisenter, int userid) {  //活动订单
        Service service = retrofit.create(Service.class);
        Call<TrainOrder> call = service.trainOrderlist(userid);
        Callback<TrainOrder> callback = new Callback<TrainOrder>() {
            @Override
            public void onResponse(Call<TrainOrder> call, Response<TrainOrder> response) {
                TrainOrder activitys = response.body();
                lisenter.onSuccess(activitys);
            }
            @Override

            public void onFailure(Call<TrainOrder> call, Throwable t) {
                lisenter.onFailure();
            }
        };
        call.enqueue(callback);
    }


}
